#include <string>
#include <vector>
#include <iostream>
using std::vector;
using std::string;
using std::cout;
using std::endl;
using std::ostream;

template<typename T>
struct Aligner{
    union{
        long double long_double_;
        long long_;
        void (*simple_function_ptr)();
    };
};
    
template<typename T>
class Map{
    template<typename U>
    struct Pair{
        string name;
        union{
            char raw_mem[sizeof(U)];
            Aligner<U> dummy;
        }val;
        Pair(string n = ""):name(n){}
        
        Pair& operator=(const U& v){
            new(val.raw_mem) U(v);
            return *this;
        }
    };
    vector<Pair<T> > vec;
    Map(const Map&);
    Map& operator=(const Map&);
    typedef typename vector<Pair<T> >::const_iterator CIT;
    typedef typename vector<Pair<T> >::iterator IT;
public:
    Map(){}
    Pair<T>& operator[](const string&);
    void print_all()const;
};
template<typename T>
Map<T>::Pair<T>& Map<T>::operator[](const string& name)
{
    IT it = vec.begin();
    IT end = vec.end();
    for(; it != end; ++it){
        if(it->name == name) return *it;
    }
    vec.push_back(Pair<T>(name));
    return vec.back();
}
template<typename T>
void Map<T>::print_all()const
{
    for(CIT p = vec.begin(); p != vec.end();++p){
        cout << p->name << ": " << *(T*)(&p->val.raw_mem[0]) << endl;
    }
}
struct stu{
    string name;
    string id;
    stu(string n, string i):name(n), id(i){}
    //stu(){}
};
ostream& operator<<(ostream& os, const stu& s)
{
    return os << " Name: " << s.name << " Id: " << s.id ;
}

int main()
{
    Map<stu> m;
    m["first"] = stu("Zhubicen","011062");
    m.print_all();
}








